<?php
class kucun_areaControl extends skymvc{
	
	public function __construct(){
		parent::__construct();
	}
	
	public function onDefault(){
		$kcid=get_post('shopid','i');
		$kucun=M("kucun")->selectRow("kcid=".$kcid);
		$sclist=M("sites")->select(array(
			"limit"=>100000
		));
		$scids=M("kucun_area")->selectCols(array(
			"where"=>" kcid=".$kcid,
			"fields"=>"siteid",
			"limit"=>100000
		));
		 
		 
		 
		 
			foreach($sclist as $k=>$v){				 
				  if($scids){
					  if(in_array($v['siteid'],$scids)){
						  $v['isdo']=1;
					  }else{
						 $v['isdo']=0; 
					  }
				  }
				  $sclist[$k]=$v;
				      				
			}
		
		$this->smarty->assign(array(
			"sclist"=>$sclist,
			"kucun"=>$kucun,
			"scids"=>$scids
		));
		$this->smarty->display("kucun_admin/area.html");
	}
	
	public function onShouquan(){
		$siteid=get_post('siteid','i');
		$kcid=get_post('kcid','i');
		$row=M("kucun_area")->selectRow("siteid=".$siteid." AND kcid=".$kcid);
		if($row){
			$this->goALl("授权失败",1);
		}
		M("kucun_area")->insert(array(
			 
			"dateline"=>time(),
			"siteid"=>$siteid,
			"kcid"=>$kcid,
			 
		));
		$this->goALl("授权成功");
	}
	
	public function onQxSHouquan(){
		$siteid=get_post('siteid','i');
		$kcid=get_post('kcid','i');
		M("kucun_area")->delete("siteid=".$siteid." AND kcid=".$kcid);
		$this->goALl("取消授权成功");
	}
	
}
?>